﻿using System;
using System.Text;
using RoketSolutions.SP2010.Infrostructure.UI.Ajax.Abstractions;

namespace RoketSolutions.SP2010.Infrostructure.UI.Ajax.ActionResults
{
    public class ContentResult : ActionResult
    {
        public String Content
        {
            get;
            set;
        }

        public String ContentType
        {
            get;
            set;
        }

        public Encoding Encoding
        {
            get; 
            set;
        }

        public ContentResult(String content)
        {
            Content = content;
        }

        public ContentResult(String content, String contentType, Encoding encoding)
        {
            Content = content;
            ContentType = contentType;
            Encoding = encoding;
        }

        public override void Execute(ControllerContext context)
        {
            if(context != null)
            {
                var response = context.HttpContext.Response;

                if (!String.IsNullOrEmpty(ContentType))
                    response.ContentType = ContentType;

                if (Encoding != null)
                    response.ContentEncoding = Encoding;

                if(Content != null)
                    response.Write(Content);
            }
        }
    }
}
